import pyppeteer
import pyautogui
import win32gui

# 获取当前活动窗口的句柄
hwnd = win32gui.GetForegroundWindow()


# 使用pyppeteer附加到这个窗口
async def attach_to_window(hwnd):
    # 等待窗口加载
    await pyppeteer.launch()
    browser = await pyppeteer.attach_to_chrome(hwnd)
    page = await browser.newPage()

    # 获取页面上所有的list标签
    lists = await page.querySelectorAllEval('list', 'nodes => nodes.map(node => node.innerText)')

    # 打印list标签的内容
    for list_content in lists:
        print(list_content)

    # 关闭浏览器
    await browser.close()


# 运行函数
attach_to_window(hwnd)